 <template>
  <div>
    <h1>组件通信-父组件</h1>
    <h3>{{ count }}</h3>
    <button @click="count++">count++</button>
    <hr />
    <Child @change-obj="changeobj" :count="count" :obj="obj" />
  </div>
</template>

<script>
import Child from './components/child.vue'
import { ref, provide } from 'vue'
export default {
  components: {
    Child
  },
  setup () {
    const count = ref(1)
    const obj = ref({ name: '大哥', age: 18 })
    // 提供数据（注入数据）=> 写法：provide('共享数据名字',变量)
    provide('count1', count)
    // 子传父的回调函数
    const changeobj = (cg) => {
      obj.value.age = cg
    }
    return { count, obj, changeobj }
  }
}
</script>

<style lang="scss" scoped>
</style>
